package it.virtuscarroccio.com.webapp.controller;

import it.virtuscarroccio.com.Constants;
import it.virtuscarroccio.com.model.User;
import it.virtuscarroccio.com.service.NewsManager;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;


/**
 * @author <a href="mailto:flavio.ricci82@gmail.com">Flavio Ricci</a>
 */
public class NewsController implements Controller {
    private transient final Log log = LogFactory.getLog(NewsController.class);
    private NewsManager newsManager = null;

    public void setNewsManager(NewsManager newsManager) {
        this.newsManager = newsManager;
    }

    public ModelAndView handleRequest(HttpServletRequest request,
                                      HttpServletResponse response)
    throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'handleRequest' method...");
        }

        ModelAndView mv = new ModelAndView();
        mv.addObject("newsList", newsManager.getAllNews());
        mv.setViewName("admin/newsList");
        return mv;
    }
}
